package com.zhao.fishingguideserver.service.impl;

import com.zhao.fishingguideserver.mapper.DashboardMapper;
import com.zhao.fishingguideserver.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据看板服务实现类
 */
@Service
public class DashboardServiceImpl implements DashboardService {
    
    @Autowired
    private DashboardMapper dashboardMapper;
    
    @Override
    public Map<String, Object> getSummary() {
        Map<String, Object> summary = new HashMap<>();
        
        // 用户数据
        summary.put("totalUsers", dashboardMapper.countTotalUsers());
        summary.put("todayNewUsers", dashboardMapper.countTodayNewUsers());
        
        // 商城数据
        summary.put("totalProducts", dashboardMapper.countTotalProducts());
        summary.put("availableProducts", dashboardMapper.countAvailableProducts());
        summary.put("totalOrders", dashboardMapper.countTotalOrders());
        summary.put("todayOrders", dashboardMapper.countTodayOrders());
        summary.put("totalAmount", dashboardMapper.countTotalAmount());
        summary.put("todayAmount", dashboardMapper.countTodayAmount());
        
        // 社区数据
        summary.put("totalPosts", dashboardMapper.countTotalPosts());
        summary.put("todayNewPosts", dashboardMapper.countTodayNewPosts());
        summary.put("totalComments", dashboardMapper.countTotalComments());
        summary.put("totalLikes", dashboardMapper.countTotalLikes());
        
        // 商品状态统计
        summary.put("productsByStatus", dashboardMapper.countProductsByStatus());
        
        // 订单状态统计
        summary.put("ordersByStatus", dashboardMapper.countOrdersByStatus());
        
        return summary;
    }
    
    @Override
    public List<Map<String, Object>> getUserGrowthTrend() {
        return dashboardMapper.selectUserGrowthTrend();
    }
    
    @Override
    public List<Map<String, Object>> getSalesTrend() {
        return dashboardMapper.selectSalesTrend();
    }
    
    @Override
    public List<Map<String, Object>> getPostTrend() {
        return dashboardMapper.selectPostTrend();
    }
    
    @Override
    public List<Map<String, Object>> getHotPosts() {
        return dashboardMapper.selectHotPosts();
    }
    
    @Override
    public List<Map<String, Object>> getActiveUsers() {
        return dashboardMapper.selectActiveUsers();
    }
}

